package com.rentplant;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.rentplant.service.impl.*;
import com.rentplant.Pojo.user;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit4.SpringRunner;

@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@Rollback(value = false)
@RunWith(SpringRunner.class)
public class sureUser extends ApplicationTest {
//    用户身份验证测试
    @Autowired
    private userServiceImp userserviceimp;
    @Test
    public void test(){

        System.out.println("待插入的用户数据");
        user userinfo = new user("xidnjgndfi-asdnjkcnxv","喜相连","http://127.0.0.1:8080/image/download?name=c0408012-219e-44ce-8fd0-f7763faa24b8.jpg",
                                "我是测试","男","1000000","20190200452","管理学院","工商管理"
                                ,"A2011","学生用户",0,"待审核");
        JSONObject info = (JSONObject) JSON.toJSON(userinfo);
//        对应sql使用的数据属性名
        info = (JSONObject) JSON.parse(JSON.toJSONString(info).replace("userId","openid"));
        info = (JSONObject) JSON.parse(JSON.toJSONString(info).replace("nickName","nickname"));
        info = (JSONObject) JSON.parse(JSON.toJSONString(info).replace("wxAva","ava"));
        info = (JSONObject) JSON.parse(JSON.toJSONString(info).replace("userName","name"));
        info = (JSONObject) JSON.parse(JSON.toJSONString(info).replace("userGender","gender"));
        info = (JSONObject) JSON.parse(JSON.toJSONString(info).replace("phone","number"));

        boolean result = userserviceimp.addUser(info);
        System.out.println(result);
    }
}
